﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IsikFx.Project.Core;
using IsikFx.Project.Utils;
using IsikFx.Project.CommonTypes.CRUD;
using IsikFx.Project.CommonTypes.Announcement;
using IsikFx.Project.CommonTypes.Fund;
using IsikFx.Project.CommonTypes.FundLog;
using IsikFx.Project.CommonTypes.User;
using IsikFx.Project.CommonTypes.Watchman;
using IsikFx.Project.CommonTypes;
namespace IsikFx.Project.ClientApp.Helpers
{
    public class WcfTypeInvoker : IWcfDataProvider
    {
        TypeInvoker invoker = new TypeInvoker();

        public Type ServiceType
        {
            get
            {
                try
                {
                    string typeName = System.Configuration.ConfigurationManager.AppSettings["WcfServiceType"];
                    return Type.GetType(typeName, true);
                }
                catch (Exception ex)
                {
                    ExceptionHelper.HandleException(ex, this.GetType());
                    throw;
                }
            }
        }

        public bool? WcfIsAlive()
        {
            return (bool)invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.WcfIsAlive, null);
        }

        public bool CheckFirstLogin(string domainName)
        {
            return (bool)invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.CheckFirstLogin, domainName);
        }

        public CrudResponseMessage InsertNewFund(string domainName, string fundAmount, int fundDate, int fundMonth, int fundYear)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.InsertNewFund, domainName, fundAmount, fundDate, fundMonth, fundYear) as CrudResponseMessage;
        }

        public FundResponseMessage GetNewFunds()
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetNewFunds, null) as FundResponseMessage;
        }

        public CrudResponseMessage UpdateShownFunds(int id)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.UpdateShownFunds, id) as CrudResponseMessage;
        }

        public CrudResponseMessage UpdateUserAccount(int id)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.UpdateUserAccount, id) as CrudResponseMessage;
        }

        public int GetUserIDFromDomain(string domainName)
        {
            return (Int32)invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetUserIDFromDomain, domainName);
        }

        public CrudResponseMessage UpdateUserRole(int id, int salesOrRetaintion)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.UpdateUserRole, id, salesOrRetaintion) as CrudResponseMessage;
        }

        public CrudResponseMessage InsertNewUser(string name, string surname, int teamId, int role, string domainName)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.InsertNewUser, name, surname, teamId, role, domainName) as CrudResponseMessage;
        }

        public UserResponseMessage GetCurrentUser(string domainName)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetCurrentUser, domainName) as UserResponseMessage;
        }

        public CrudResponseMessage CreateNewCustomer(int agentID, string customerName, string customerSurname, string loginNo, string accountOpenDate, string firstFundDate, string firstFundAmount, string currencyType)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.CreateNewCustomer, agentID, customerName, customerSurname, loginNo, accountOpenDate, firstFundDate, firstFundAmount, currencyType) as CrudResponseMessage;
        }

        public List<Customer> GetCustomers(int agentID)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetCustomers, agentID) as List<Customer>;
        }

        public UserResponseMessage GetUsersByRole(int role)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetUsersByRole, role) as UserResponseMessage;
        }

        public CrudResponseMessage UpdateFundShownStatus(int id)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.UpdateFundShownStatus, id) as CrudResponseMessage;
        }

        public bool Test()
        {
            return (bool)invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.Test, null);
        }

        public CrudResponseMessage UpdateAgentGoal(int agentID, string fundGoal, string accountGoal, string currencyType, bool insert)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.UpdateAgentGoal, agentID, fundGoal, accountGoal, currencyType, insert) as CrudResponseMessage;
        }

        public Goal GetAgentGoal(int agentID)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetAgentGoal, agentID) as Goal;
        }

        public GoalProgress GetGoalProgress(int agentID)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetGoalProgress, agentID) as GoalProgress;
        }

        public AnnouncementResponseMessage GetActiveAnnouncementsAsAdmin(int adminID)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetActiveAnnouncementsAsAdmin, adminID) as AnnouncementResponseMessage;
        }

        public AnnouncementResponseMessage GetActiveAnnouncementsAsUser(int roleType)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetActiveAnnouncementsAsUser, roleType) as AnnouncementResponseMessage;
        }

        public CrudResponseMessage InsertAnnouncement(int adminID, string announcementID, string announcementTitle, string announcement, string createDate, int roleType)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.InsertAnnouncement, adminID, announcementID, announcementTitle, announcement, createDate, roleType) as CrudResponseMessage;
        }

        public CrudResponseMessage ResetGoals()
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.ResetGoals, null) as CrudResponseMessage;
        }

        public CrudResponseMessage DeleteAnnouncement(int id)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.DeleteAnnouncement, id) as CrudResponseMessage;
        }

        public CrudResponseMessage UpdateWatchmenTable(List<CommonTypes.Watchman.Watchman> watchManList)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.UpdateWatchmenTable, watchManList) as CrudResponseMessage;
        }

        public WatchmanResponseMessage GetWatchmenList(string watchmanDate)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetWatchmenList, watchmanDate) as WatchmanResponseMessage;
        }

        public CrudResponseMessage SaveUsersPhoto(string fileName, byte[] stream)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.SaveUsersPhoto, fileName, stream) as CrudResponseMessage;
        }

        public FundLogResponseMessage GetMinusFundLogs(string userID, string date)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetMinusFundLogs, userID, date) as FundLogResponseMessage;
        }

        public FundLogResponseMessage GetPlusFundLogs(string userID, string date)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetPlusFundLogs, userID, date) as FundLogResponseMessage;
        }

        public FundLogResponseMessage GetAllFundLogs(string userID, string date)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.GetAllFundLogs, userID, date) as FundLogResponseMessage;
        }

        public CrudResponseMessage InsertFundLog(string userID, string fundAmount, int isFundOut, string fundDate, string fundTime)
        {
            return invoker.InvokeService(ServiceType, IsikFxConstants.OperationNameConstants.InsertFundLog, userID, fundAmount, isFundOut, fundDate, fundTime) as CrudResponseMessage;
        }
    }
}
